// Fill out your copyright notice in the Description page of Project Settings.


#include "MoveActorController.h"
#include "MoveActor.h"

// Sets default values
AMoveActorController::AMoveActorController()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;
	time = 2;

}

void AMoveActorController::SpawnMoveActor()
{
	float x, y;
	x = rand() % 2001 - 1000;
	y = rand() % 2001 - 1000;
	FActorSpawnParameters ActorSpawnParameters;
	GetWorld()->SpawnActor<AMoveActor>(FVector(x,y,0), FRotator(0), ActorSpawnParameters);
	GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Blue, FString::Printf(TEXT("x=%f"), x));
	GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Blue, FString::Printf(TEXT("y=%f"), y));
}

// Called when the game starts or when spawned
void AMoveActorController::BeginPlay()
{
	Super::BeginPlay();
	SpawnMoveActor();
	FTimerHandle TimerHandle;
	FTimerDelegate TimerDelegate = FTimerDelegate::CreateUObject(this, &AMoveActorController::SpawnMoveActor);
	GetWorldTimerManager().SetTimer(TimerHandle, TimerDelegate, time, true);
	
}

// Called every frame
void AMoveActorController::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

